#include "StdAfx.h"
#include "CallBacks.h"
#include "ServiceFunctions.h"
#include "Maze.h"

extern CMaze *g_theMaze;

void myDisplay()
{
	glClear(GL_COLOR_BUFFER_BIT);

	g_theMaze->Draw();

	glFlush();
}

void myKeyboard(unsigned char theKey, int mouseX, int mouseY)
{
	switch(theKey)
	{
		case 'c' :
		{
			if(!g_theMaze->Created())
			{
				g_theMaze->FormMaze();
			}
			else
			{
				MessageBox(NULL, "The Maze is already created", "Information", MB_OK | MB_ICONINFORMATION);
			}
			break;
		}
		case 'r' :
		{
			if(g_theMaze->Created())
			{
				if(!g_theMaze->RouteFound())
				{
					bool found = g_theMaze->TraceRoute();

					if(found)
					{
						g_theMaze->DrawRoute();

						MessageBox(NULL, "The route is found !!!", "Success", MB_OK | MB_ICONINFORMATION);
					}
					else
					{
						MessageBox(NULL, "The route is NOT found !!!", "Failure", MB_OK | MB_ICONINFORMATION);
					}
				}
				else
				{
					MessageBox(NULL, "The route is ALREADY found !!!", "Warning", MB_OK | MB_ICONINFORMATION);
				}
			}
			else
			{
				MessageBox(NULL, "The Maze is not created,\npress 'c' to start creation", "Warning", MB_OK | MB_ICONINFORMATION);
			}
			
			break;
		}
		case 's' :
		{
			g_theMaze->SaveMazeToFile("e:\\maze.txt");
			MessageBox(NULL, "The maze data is saved to file !!!", "Success", MB_OK | MB_ICONINFORMATION);
			break;
		}
	}
}

